<template>
  <div class="loginPage">
    <canvas
      id="canvas"
      style="display: block"></canvas>
    <div class="loginBox">
      <div class="title">
        <h1>DRH&nbsp;·&nbsp;人力资源管理系统</h1>
        <p>Strive Everyday</p>
      </div>
      <el-space
        direction="vertical"
        size="large">
        <el-input
          v-model="loginMessage.phone"
          :placeholder="$t('login.phone')" />
        <el-input
          v-model="loginMessage.password"
          type="password"
          show-password
          :placeholder="$t('login.password')" />
        <el-button
          type="primary"
          @click="login">
          {{ $t('login.loginBtn') }}
        </el-button>
      </el-space>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import useStore from '@/store'
import initLoginBg from '@/utils/intiLoginBg'
import { setToken, setTokenTime } from '@/utils/token'

const router = useRouter()
const { appStore } = useStore()
const loginMessage = ref<LoginMessage>({
  phone: '13708171317',
  password: '123456'
})

const login = () => {
  appStore.isLogin = true
  router.replace('/home')
  setTokenTime()
  setToken('123')
  ElMessage({
    message: '登陆成功',
    type: 'success',
    showClose: true
  })
}

onMounted(() => {
  initLoginBg()
  window.onresize = function () {
    initLoginBg()
  }
})
</script>

<style lang="less" scoped>
.loginPage {
  position: relative;
  .loginBox {
    width: 450px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: #fff;

    h1 {
      font-weight: bold;
      font-size: 22px;
      text-align: center;
      color: #fff;
    }
    p {
      text-align: center;
      margin: 20px 0;
    }
    .title {
      margin-bottom: 40px;
      position: relative;
      &:before,
      &:after {
        content: '';
        width: 100px;
        height: 2px;
        position: absolute;
        background: linear-gradient(to right, rgba(255, 255, 255, 0), #1976d2);
        left: -20px;
        top: 18px;
      }
      &:after {
        left: auto;
        background: linear-gradient(to left, rgba(255, 255, 255, 0), #1976d2);
        right: -20px;
      }
    }
    .el-space {
      width: 100%;
      :deep(.el-space__item) {
        width: 100%;
      }
      .el-input {
        :deep(.el-input__wrapper) {
          background-color: rgba(255, 255, 255, 0);
          box-shadow: 0 0 0 0px
            var(--el-input-border-color, var(--el-border-color)) inset;
          height: 38px;
          outline: none;
          border: 1px #409eff solid !important ;
          .el-input__inner {
            color: #fff !important;
          }
        }
      }
    }
  }
}
</style>
